/*
 * @Author: wy
 * @Date: 2021-02-09 16:32:07
 * @LastEditTime: 2021-03-16 15:59:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \radio-web\src\utils\globalMethods.js
 */
const init = (vue) => {
  /**
   *  计算table高度
   * @param {*} formType 根据页面上部操作区的行数计算表格要显示的高度，确保整体页面在一屏显示
   * @returns height
   */
  vue.prototype.$baseTableHeight = (formType) => {
    let height = window.innerHeight
    const paddingHeight = 300
    const formHeight = 55
    // if (typeof formType === 'number') {
    //   height = height - paddingHeight + formHeight * formType
    // } else {
    //   height = height - paddingHeight
    // }
    if (formType === 1) { // 1行
      height = height - paddingHeight + formHeight
    } else if (formType === 2) { // 2行 以两行为基准，上下各自加减
      height = height - paddingHeight
    } else if (formType === 3) { // 3行
      height = height - paddingHeight - formHeight
    }
    return height
  }
  // await处理异常，对数据二次处理并返回
  vue.prototype.$await = (promise) => {
    return promise.then(res => {
      if (res && res.data.resp_code === 0) {
        return [null, res.data]
      } else {
        return [res, null]
      }
    }).catch(err => {
      return [err, null]
    })
  }
}
if (typeof window !== 'undefined' && window.Vue) {
  init(window.Vue)
}

export default init
